package kr.hkit.androidcomplete01.chapter08;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

public class MoveCircleEx extends Activity {
	MyView vw;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		vw = new MyView(this);
		vw.setFocusable(true);
		vw.setFocusableInTouchMode(true);
		setContentView(vw);
	}
	
	class MyView extends View{
		float mX, mY;
		int mColor;
		
		public MyView(Context context) {
			super(context);
			mX = 100;
			mY = 100;
			mColor = Color.BLUE;
		}

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			
			if(event.getAction() == MotionEvent.ACTION_DOWN){
				mX = event.getX();
				mY = event.getY();
				invalidate();
				return true;
			}
			return false;
		}

		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
			canvas.drawColor(Color.LTGRAY);
			Paint pnt = new Paint();
			pnt.setColor(mColor);
			pnt.setAntiAlias(true);
			canvas.drawCircle(mX, mY, 16, pnt);
		}
	}
}
